<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面</title>
    <script src="../util/axios.min.js"></script>
    <style>
        /* 重置默认的边距和填充 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background: url('../images/vmbg2.png') center/cover no-repeat fixed; /* 使用背景图像 */
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .login-container {
            text-align: center;
        }

        .login-card {
            background: rgba(255, 255, 255, 0.8); /* 添加半透明的背景颜色 */
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
            border-radius: 8px;
            padding: 20px;
            width: 300px;
            max-width: 100%;
        }

        .login-card h2 {
            color: #333;
        }

        .input-container {
            margin-bottom: 20px;
        }

        label {
            display: block;
            text-align: left;
            color: #555;
            font-weight: bold;
        }

        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }

        .password-toggle {
            position: absolute;
            top: 50%;
            right: 10px;
            transform: translateY(-50%);
            cursor: pointer;
        }

        .button-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        button {
            background: linear-gradient(to right, #007bff, #0056b3);
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s ease;
        }

        button:hover {
            background: linear-gradient(to left, #007bff, #0056b3);
        }

        p {
            margin-top: 10px;
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="login-card">
        <h2>登录</h2>
        <form>
            <div class="input-container">
                <label for="username">用户名</label>
                <input  type="text" id="username"  placeholder="请输入用户名" required>
            </div>

            <div class="input-container">
                <label for="password">密码</label>
                <input  type="password" id="password"  placeholder="请输入密码" required>
                <span class="password-toggle"></span>
            </div>

            <div class="button-container">
                <button type="button" onclick="login()">登录</button>
                <button type="button" onclick="register()">注册</button>
            </div>
        </form>
    </div>
</div>
</body>
<script >
    function login() {
        const username=document.getElementById("username").value
        const password=document.getElementById("password").value
        axios({
            method: 'post',
            url: 'http://localhost:8080/user/login',
            data: {
                username: username,
                password: password
            }
        }).then((resp)=>{
            if (resp.data.code===200){
                localStorage.setItem("token", resp.data.data)
                alert("登陆成功")
                window.location.href="main.html";
            }else{
                alert(resp.data.message)
            }


        });
    }
    function register() {
        location.href="register.html";
    }
</script>
</html>
